<!doctype html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>有奖答题平台</title>
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"/>
    <link rel="stylesheet" href="/lib/mobile/css/common.css?111"/>
    <link rel="stylesheet" href="/lib/mobile/css/point.css?0000"/>
    <link rel="stylesheet" href="/mobile/css/bui.css" />
</head>
<body>
<div class="main">
    <ul class="point_list" id="point_list">

    </ul>
    <div class="point_caption">
        <dl>
            <dt><strong>当日积分：<b id="rpoint">5</b></strong><span style="margin-right: 40px;"><input type="text" id="date" style="width: 150px;font-size: 16px" readonly class="bui-input"></span></dt>
            <dd><span id="ypoint"></span><span id="npoint"></span></dd>
        </dl>
    </div>
    <ul class="bui-list point_timeline">
        <div id="ywclist" class="bui-scroll">
            <div class="bui-scroll-head"></div>
            <div class="bui-scroll-main">
                <ul class="bui-list bui-list-thumbnail" id="ddlb">

                </ul>
            </div>
            <div class="bui-scroll-foot"></div>
        </div>
    </ul>
    <ul class="bottom_menu">
        <li  id="indexsy"><a href="javascript:void(0);">首页</a></li>
        <!--<li>|</li>-->
        <li  id="hdrule"><a href="javascript:void(0);">活动规则</a></li>
        <!--<li  id="point_rule"><a href="javascript:void(0);">积分规则</a></li>-->
        <!--<li>|</li>-->
        <!--<li id="prize_rule"><a href="javascript:void(0);">抽奖规则</a></li>-->
        <!--<li>|</li>-->
        <li id="center"><a href="javascript:void(0);">个人中心</a></li>
    </ul>
</div>
<!-- 依赖库 手机调试的js引用顺序如下 -->
<script src="/lib/mobile/js/zepto.js"></script>
<script src="/lib/mobile/js/plugins/fastclick.js"></script>
<script src="/lib/mobile/js/bui.js"></script>
<script src="/lib/mobile/js/common.js?1110    "></script>
<script>
    var uid;
    bui.ready(function () {
        // 这里写业务及控件初始化
        var storage = bui.storage();
        var uid=storage.get("uid");
        uid=uid[0];
        dateSelect(uid);
        bui.btn({id: ".bui-page", handle: ".bui-btn"}).load();
        var pageview = {};
        pageview.init = function () {
            //我的积分
            getDayAnswerList(uid,'');
            getMyPointList(uid,'');
            getPointBar(uid,'');
        }
        pageview.init();
    })

    function getDayAnswerList(uid,rq){
        bui.list({
            id: "#ywclist",
            url: BASE_URL+"mobile/getDayAnswerList",
            pageSize: 5,
            data:
                {
                    uid:uid,
                rq:rq
                },
            field: {
                page: "page",
                size: "pageSize",
                data: "data"
            },
            callback: function(e) {
                // e.target 为你当前点击的元素
                // e.currentTarget 为你当前点击的handle 整行
            },
            template: function(data) {
                var html = "";
                for(var i=0;i<data.length;i++){
                    var tmsl=data[i].tmsl;
                    var dtsl=data[i].dtsl;
                    var rq=data[i].rq;
                    var point=data[i].point;
                        html=html+"<dl>\n" +
                            "            <dt>"+rq+"</dt>\n" +
                            "            <dd>\n" +
                            "                <span>每日答题</span>\n" +
                            "                <em><strong>+"+point+"</strong>分</em>\n" +
                            "            </dd>\n" +
                            "        </dl>";
                }
                return html;
            },
            onBeforeRefresh: function() {
                // console.log("brefore refresh")
            },
            onBeforeLoad: function() {
                // console.log("brefore load")
            },
            onRefresh: function() {
                // 刷新以后执行
                // console.log("refreshed")
            },
            onLoad: function() {
                // 刷新以后执行
                // console.log("loaded")
            }
        })
    }
    function getMyPointList(uid,rq) {
        //执行登录操作
        var loginAjax = bui.ajax({
            url: BASE_URL+"mobile/getMyPointList",
            // 可选参数
            data: {
                uid:uid,
                rq:rq
            },
            method: "POST"
        });
        loginAjax.then(function(res) {

            if(res.code == 0){
                var user = res.data;
                if(user.rpoint) {
                    $("#rpoint").html(user.rpoint);
                }else{
                    $("#rpoint").html("0");
                }
                if(user.ypoint){
                    $("#ypoint").html("本月积分："+user.ypoint);
                }else{
                    $("#ypoint").html("本月积分："+0);
                }
                if(user.npoint){
                    $("#npoint").html("年度积分："+user.npoint);
                }else{
                    $("#npoint").html("年度积分："+0);
                }
                // $("#ypoint").html("本月积分："+user.ypoint);
                // $("#npoint").html("年度积分："+user.npoint);
            }else{
                bui.alert(res.msg);
            }
        },function(res) {
            bui.alert("请求异常");
        })
    }
    function getPointBar(uid,rq) {
        //执行登录操作
        var loginAjax = bui.ajax({
            url: BASE_URL+"mobile/getPointBar",
            // 可选参数
            data: {
                uid:uid,
                rq:rq,
                ts:4
            },
            method: "POST"
        });
        loginAjax.then(function(res) {
            // console.log(res)
            if(res.code == 0){
                var user = res.data.data;
                var html=''
                for(var i=0;i<user.length;i++){
                    if(i==0){
                        html=html+"<li>\n" +
                            "                        <dl>\n" +
                            "                        <dt>今日</dt>\n" +
                            "                        <dd><p style=\"height: "+user[0].point+"%;\"><strong>"+user[0].point+"分</strong></p></dd>\n" +
                            "                        </dl>\n" +
                            "                        </li>";
                    }else if(i>=1){
                        html=html+"<li>\n" +
                            "                        <dl>\n" +
                            "                        <dt>"+user[i].rq+"</dt>\n" +
                            "                        <dd><p style=\"height: "+user[i].point+"%;\"><strong>"+user[i].point+"分</strong></p></dd>\n" +
                            "                        </dl>\n" +
                            "                        </li>";
                    }

                }

                $("#point_list").html(html);
            }else{
                bui.alert(res.msg);
            }
        },function(res) {
            bui.alert("请求异常");
        })
    }
    function dateSelect(uid) {
        var uiPickerdate = bui.pickerdate({
            handle: "#date",
            bindValue: true, // 1.5.3 新增, 修改的值会自动绑定到 handle, 不再需要自己去绑定
            // input 显示的日期格式
            formatValue: "yyyy-MM-dd",
            onChange: function(value) {
            },
            callback: function(e) {
                getDayAnswerList(uid,this.value());
                getMyPointList(uid,this.value());
                // console.log(uid+"=="+this.value());
                getPointBar(uid,this.value());
            },
            // 如果不需要按钮,设置为空
            // buttons: [{name:"取消"}]
        });
        uiPickerdate.cols({
            hour: "none",
            minute: "none",
            second: "none"
        })
    }
</script>
</body>
</html>